<?php

use think\migration\Seeder;

class SourceStationForecastData extends Seeder
{
    public function run()
    {
        $rows = [];
        $num = 168;
        $i = 0;
        while ($num > 0) {
            $rows[] = [
                'date' => date('Y-m-d H', time() + 3600 * $i).':00:00',   //预报时间-7天168小时
                'no2'          => mt_rand(0, 200),   //二氧化氮
                'pm25'         => mt_rand(0, 200),   //PM25
                'o3'           => mt_rand(0, 200),   //臭氧
                'so2'          => mt_rand(0, 200),   //二氧化硫
                'pm10'         => mt_rand(0, 200),   //PM10
                'aqi'          => mt_rand(0, 200),   //aqi
                'co'           => mt_rand(0, 200),   //一氧化碳

            ];
            $num--;
            $i++;
        }

        $data = json_encode($rows, true);

        $table = $this->table('source_bureau_air_quality_station_forecast');
        $rows = [
            //5个站点
            [
                'site_name'      => 'CZBZ',
                'data'           => $data,
                //'data'         => $this->data(), //原json数据
                'predict_time'   => date('Y-m-d H', time() + 3600 * $i) . ':00:00',   //预报时间-7天168小时
                'publish_time'   => date('Y-m-d H', time()) . ':00:00',                           //发布时间-7天168小时
                'create_time'    => date('Y-m-d H:i:s', time()),
                'is_to_tsinghua' => '1',
            ],
        ];
        $table->insert($rows)->save();
    }

    //测试数据
    public function demo()
    {
        // $dataDemo = [
        //     [
        //         'date' => '2019-01-22 12:00:00',
        //         //六参
        //         'no2'  => 20.0,
        //         'pm25' => 35.0,
        //         'o3' => 81.0,
        //         'so2' => 40.0,
        //         'pm10' => 45.0,
        //         'co' => 0.6,
        //         //aqi
        //         'aqi' => 50.0,
        //     ]
        // ];

        //7天168条数据
        $data = file_get_contents(__DIR__ . '/json/weather.json');
        return $data;
    }
}
